package kafka;

import cn.sh.yhk.Application;
import cn.sh.yhk.configure.kafka.KafkaSendResultHandler;
import com.alibaba.fastjson.JSONObject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @Auther: adminyhk
 * @Date: 2018/12/7 10:22
 * @Description:
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
public class KafkaSender {
    @Resource
    private KafkaTemplate<String, Object> kafkaTemplate;
    //
//    @Resource
//    private RedisTemplate redisTemplate;
//
    @Resource
    private KafkaSendResultHandler producerListener;

    @Test
    public void init() throws IOException {
//        redisTemplate.setEnableTransactionSupport(true);
//        redisTemplate.multi();
//        ValueOperations<String, Object> valueOperations = redisTemplate.opsForValue();
//        valueOperations.set("99", "34");
//        redisTemplate.exec();
        kafkaTemplate.setDefaultTopic("sk_od");
        System.out.println(kafkaTemplate.getDefaultTopic().length());
//        System.out.println(kafkaTemplate.getDefaultTopic());
//        Map news = new HashMap();
//        news.put("Title", "中国产小型无人机的对手来多");
//        news.put("tag", "军事121213423tyrgfdwegrhtgnfd");
//        news.put("PublishTime", "2018-01-24T23:59:30Z");
//        kafkaTemplate.setProducerListener(producerListener);
//        kafkaTemplate.send("sk_od", JSONObject.toJSONString(news));
//        System.out.println("as");
    }

}